Added CAGradientLayer, getting this in my UIView dealloc: [CALayer release]: message sent to deallocated instance
Posted
by
developerdoug
on Stack Overflow
See other posts from Stack Overflow
or by developerdoug
Published on 2012-09-08T18:47:37Z
Indexed on
2012/09/08
21:38 UTC
Read the original article
Hit count: 205
Here there,
I have a custom UIView. This view acts as a activity indicator but as label above the UIActivityIndicatorView. In the init, I add a CAGradientLayer. I allocate and initialize it and insert it at index 0 as a sublayer of the UIView layer property. In my dealloc method was called, I received a message in the console:
- [CALayer release]: message sent to deallocated instance.
My code:
@interface LabelActivityIndicatorView ()
{
UILabel *_label;
UIActivityIndicatorView *_activityIndicatorView;
CAGradientLayer *_gradientLayer;
}
@end
@implementation LabelActivityIndicatorView
//dealloc
- (void) dealloc
{
[_label release];
[_activityIndicatorView release];
//even tried to remove the layer
[_gradientLayer removeFromSuperLayer];
[_gradientLayer release];
[super dealloc];
}
// init
- (id) initWithFrame:(CGRect)frame
{
if ( (self = [super initWithFrame:frame]) )
{
// init the label
// init the gradient layer
_gradientLayer = [[CAGradientLayer alloc] init];
[_gradientLayer setBounds:[self bounds]];
[_gradientLayer setPosition:CGPointMake(frame.size.width/2, frame.size.height/2)];
[[self layer] insertSublayer:_gradientLayer atIndex:0];
[[self layer] setNeedsDisplay];
}
return self;
}
@end
Anyone have any ideas. Since I'm allocating and initializing the gradient layer I'm responsible for releasing it. I should be able to alloc and init and assign to some ivar. Perhaps I should create a property with retain on it.
Thanks,
© Stack Overflow or respective owner